<?php

/**
 * @copyright Copyright &copy; Gogodigital Srls
 * @company Gogodigital Srls - Wide ICT Solutions
 * @website http://www.gogodigital.it
 * @github https://github.com/cinghie/yii2-user-extended
 * @license GNU GENERAL PUBLIC LICENSE VERSION 3
 * @package yii2-user-extended
 * @version 0.6.0
 */

/**
 * @var \yii\web\View $this
 * @var \yii\data\ActiveDataProvider $dataProvider
 * @var \backend\models\c2\entity\rbac\BeUserSearch $searchModel
 */

$this->title = \Yii::t('user', 'Users');
$this->params['breadcrumbs'][] = $this->title;

use kartik\widgets\DatePicker;
use yii\helpers\Html;
use yii\helpers\Url;

?>
<?=
\kartik\grid\GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'summary' => Yii::t('user', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{{item}} other{{items}}}.'),
    'layout' => "{items}\n{pager}",
    'containerOptions' => ['class' => 'users-pjax-container'],
    'pjaxSettings' => [
        'neverTimeout' => true,
    ],
    'responsive' => true,
    'hover' => true,
    'export' => false,
    'panel' => [
        'before' => '<span class="ml-2">' .
            Html::a('<i class="fa fa-plus"></i> ' . Yii::t('user', 'Create'), ['create'], ['class' => 'btn btn-new btn-success']
            ) . '</span><span class="mr-2;">' . '</span>',
        'type' => 'success',
        'showFooter' => false
    ],
    'columns' => [
        [
            'class' => '\kartik\grid\CheckboxColumn'
        ],
        [
            'attribute' => 'username',
            'format' => 'html',
            'hAlign' => 'center',
            'value' => function ($model) {
                $url = urldecode(Url::toRoute(['admin/update', 'id' => $model->id]));
                return Html::a($model->username, $url);
            }
        ],
        [
            'attribute' => 'firstname',
            'label' => Yii::t('user', 'Firstname'),
            'hAlign' => 'center',
            'value' => 'profile.firstname',
        ],
        [
            'attribute' => 'lastname',
            'label' => Yii::t('user', 'Lastname'),
            'hAlign' => 'center',
            'value' => 'profile.lastname',
        ],
        [
            'attribute' => 'mobile_number',
            'hAlign' => 'center',
            'value' => 'mobile_number',
        ],
        [
            'attribute' => 'email',
            'format' => 'email',
            'hAlign' => 'center',
        ],
        [
            'attribute' => 'created_at',
            // 'filterType' => \kartik\widgets\DateTimePicker::className(),
            'filter' => \kartik\widgets\DatePicker::widget([
                'model' => $searchModel,
                'type' => DatePicker::TYPE_COMPONENT_APPEND,
                'attribute' => 'created_at',
                'pluginOptions' => [
                    'todayHighlight' => true,
                    'orientation' => 'top right',
                    'zIndexOffset' => '9999',
                    'format' => 'mm/dd/yyyy',
                    'autoclose' => true,
                    'todayBtn' => true,
                ]
            ]),
            'hAlign' => 'center',
            'value' => function ($model) {
                return $model->created_at;
            },
        ],
        [
            'header' => \Yii::t('user', 'Enabled'),
            'format' => 'raw',
            'hAlign' => 'center',
            'width' => '10%',
            'value' => function ($model) {
                if ($model->isBlocked) {
                    return Html::a('<span class="fa fa-toggle-off fa-2x"></span>', ['block', 'id' => $model->id], [
                        'data-method' => 'post',
                        'data-confirm' => \Yii::t('user', 'Are you sure you want to unblock this user?'),
                    ]);
                } else {
                    return Html::a('<span class="fa fa-toggle-on fa-2x">', ['block', 'id' => $model->id], [
                        'data-method' => 'post',
                        'data-confirm' => \Yii::t('user', 'Are you sure you want to block this user?'),
                    ]);
                }
            },
        ],
        [
            'header' => \Yii::t('user', 'Actived'),
            'format' => 'raw',
            'hAlign' => 'center',
            'visible' => \Yii::$app->getModule('user')->enableConfirmation,
            'width' => '5%',
            'value' => function ($model) {
                if ($model->isConfirmed) {
                    return '<span class="fa fa-lock-open text-success"></span>';
                } else {
                    return Html::a('<span class="fa fa-lock"></span>', ['confirm', 'id' => $model->id], [
                        'data-method' => 'post',
                        'data-confirm' => \Yii::t('user', 'Are you sure you want to confirm this user?'),
                    ]);
                }
            },
        ],
    ]
])


?>
